<#--
  <template>
    <name>Kens Test template</name>
    <description>This is a test template for Ken</description>
    <promptgroups>
      <promptgroup name="table" repeatable="no" maxRepeats="0">
        <prompt>
          <type>text</type>
          <name>name</name>
          <label>Table Name</label>
          <description>The name of the table</description>
          <hint>TableNameHere</hint>
        </prompt>
        <prompt>
          <type>text</type>
          <name>namespace</name>
          <label>Table Namespace</label>
          <description>The namepsace of the table.</description>
          <hint>NameSpace</hint>
        </prompt>
        <prompt>
          <type>text</type>
          <name>brief</name>
          <label>Table Brief</label>
          <description>The brief description of the table.</description>
          <hint>Brief here</hint>
        </prompt>
        <prompt>
          <type>multiline</type>
          <name>description</name>
          <label>Table Description</label>
          <description>The description of the table.</description>
          <hint>Description here</hint>
        </prompt>
        <prompt>
          <type>text</type>
          <name>shortname</name>
          <label>Table Short Name</label>
          <description>The short name of the table</description>
          <hint>SHORTNAME</hint>
        </prompt>
        <prompt>
          <type>text</type>
          <name>prefix</name>
          <label>Table Prefix</label>
          <description>The prefix to use in naming conventions of the table</description>
          <hint>AR</hint>
        </prompt>
        <prompt>
          <type>text</type>
          <name>recordFormat</name>
          <label>Table Record Format</label>
          <description>The record format of the table</description>
          <hint>PKP10U001</hint>
        </prompt>
      </promptgroup>
      <promptgroup name="columns" repeatable="yes" maxRepeats="100">
        <prompt>
          <type>text</type>
          <name>name</name>
          <label>Column Name</label>
          <description>The name of the column</description>
          <hint>ColumnNameHere</hint>
        </prompt>
        <prompt>
          <type>text</type>
          <name>shortName</name>
          <label>Column shortname</label>
          <description>Shortname version of the field.</description>
          <hint>SHORTNAME</hint>
        </prompt>
        <prompt>
          <type>text</type>
          <name>dataType</name>
          <label>Column datatype</label>
          <description>Datatype of the column.</description>
          <hint>char(4)</hint>
        </prompt>
        <prompt>
          <type checkedValue="" uncheckedValue="NOT NULL">checkbox</type>
          <name>nullCapable</name>
          <label>Null capable?</label>
          <description>Check if the column is able to contain nulls.</description>
          <hint>checked</hint>
        </prompt>
      </promptgroup>
    </promptgroups>
  </template>
-->
/**********************************************************************
 * @brief ${table.brief}
 *
 * ${table.description}
 *
 * @author ${author}
 * @date   ${date}
 *
 * @category ${table.namespace}
 **********************************************************************
 */
 
 
/* Creating table ${table.namespace}_${table.name} */
CREATE TABLE &Library/${table.shortname} (
 
      Id
                        FOR ${table.prefix}id
                        integer
                        NOT NULL
                        GENERATED BY DEFAULT AS IDENTITY (
                         START WITH 1
                         INCREMENT BY 1
                         NO MINVALUE
                         NO MAXVALUE
                         CYCLE
                         NO ORDER
                         CACHE 20
                        ),
                        
<#list columns.repeats as column>
      ${column.name}
                       FOR ${table.prefix}${column.shortName}
                       ${column.dataType}
                       ${column.nullCapable},
</#list>  
      CreateUser
                       FOR ${table.prefix}CUSR
                       CHAR(10)
                       CCSID 37
                       NOT NULL
                       DEFAULT '',
 
      CreateJob
                       FOR ${table.prefix}CJOB
                       CHAR(10)
                       CCSID 37
                       NOT NULL
                       DEFAULT '',
 
      CreateProgram
                       FOR ${table.prefix}CPGM
                       CHAR(10)
                       CCSID 37
                       NOT NULL
                       DEFAULT '',
 
      CreateTimestamp
                       FOR ${table.prefix}CTS
                       Timestamp
                       NOT NULL
                       DEFAULT CURRENT_TIMESTAMP,
 
      UpdateUser
                       FOR ${table.prefix}UUSR
                       CHAR(10)
                       CCSID 37
                       NOT NULL
                       DEFAULT '',
 
      UpdateJob
                       FOR ${table.prefix}UJOB
                       CHAR(10)
                       CCSID 37
                       NOT NULL
                       DEFAULT '',
 
      UpdateProgram
                       FOR ${table.prefix}UPGM
                       CHAR(10)
                       CCSID 37
                       NOT NULL
                       DEFAULT '',
 
      UpdateTimestamp
                       FOR ${table.prefix}UTS
                       Timestamp
                       NOT NULL
                       FOR EACH ROW ON UPDATE AS ROW CHANGE TIMESTAMP,
 
     CONSTRAINT &library/${table.shortname}_PRIMARY_KEY
     PRIMARY KEY( Id ))
 
   RCDFMT ${table.recordFormat};
 
/* Setting system table name to ${table.namespace}_${table.name} for ${table.shortname} */
RENAME TABLE &Library/${table.shortname} TO ${table.namespace}_${table.name}
 FOR SYSTEM NAME ${table.shortname};
 
/* Setting label text for ${table.shortname} */
LABEL ON TABLE &Library/${table.shortname} IS '${table.brief}' ;
 
/* Setting column labels for ${table.shortname} */
LABEL ON COLUMN &Library/${table.shortname} (
      Id               TEXT IS 'Identifier',
      {ColumnLongName} TEXT IS '{ColumnDescription}',
      Comment          TEXT IS 'Log Comment',
      CreateUser       TEXT IS 'Create User',
      CreateJob        TEXT IS 'Create Job',
      CreateProgram    TEXT IS 'Create Program',
      CreateTimestamp  TEXT IS 'Create Timestamp',
      UpdateUser       TEXT IS 'Update User',
      UpdateJob        TEXT IS 'Update Job',
      UpdateProgram    TEXT IS 'Update Program',
      UpdateTimestamp  TEXT IS 'Update Timestamp'
);
 
/* Setting column headings for ${table.shortname} */
LABEL ON COLUMN &Library/${table.shortname} (
    Id               IS
    'Id                                                         ',
    {ColumnLongName} IS
    '                                                           ',
    CreateUser       IS
    'Create              User                                   ',
    CreateJob        IS
    'Create              Job                                    ',
    CreateProgram    IS
    'Create              Program                                ',
    CreateTimestamp  IS
    'Create              Timestamp                              ',
    UpdateUser       IS
    'Update              User                                   ',
    UpdateJob        IS
    'Update              Job                                    ',
    UpdateProgram    IS
    'Update              Program                                ',
    UpdateTimestamp  IS
    'Update              Timestamp                              '
);